package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/schema/edge"
	"entgo.io/ent/schema/field"
	"entgo.io/ent/schema/index"
)

type Weather struct {
	ent.Schema
}

func (Weather) Fields() []ent.Field {
	return []ent.Field{
		field.Int64("id").StorageKey("id"),
		field.Float("temperature"),
		field.Float("humidity").Min(0),
		field.Float("windSpeed").Default(0).Min(0),
		field.Enum("weatherCondition").Values(
			"CLEAR",
			"CLOUDY",
			"RAIN",
			"SNOW",
			"FOG",
			"STORM",
		),
		field.Float("precipitationAmount").Default(0).Min(0),
		field.Time("measurementDateTime"),
	}
}

func (Weather) Edges() []ent.Edge {
	return []ent.Edge{
		edge.To("region", Region.Type).Unique(),
		edge.To("forecast", Forecast.Type),
	}
}

func (Weather) Indexes() []ent.Index {
	return []ent.Index{
		index.Fields("temperature", "humidity", "windSpeed", "weatherCondition", "precipitationAmount"),
		index.Fields("measurementDateTime"),
		index.Edges("region"),
	}
}
